<template>
  <div>
    <!-- 1、顶部导航栏 -->
    <van-nav-bar
      fixed
      placeholder
      :title="$route.query.value + '的搜索结果'"
      left-arrow
      @click-left="$router.go(-1)"
    />
    <!-- 2/列表展示 -->
    <!-- 文章列表 -->
    <van-list
      class="article-list"
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <van-cell
        v-for="(item, index) in list"
        :key="index"
        :title="item.title"
        @click="$router.push({ path: '/article', query: { id: item.art_id } })"
      />
    </van-list>
  </div>
</template>

<script>
import { getSearch } from "./home.js";
export default {
  name: "searchResult",
  data() {
    return {
      list: [],
      loading: false,
      finished: false,
      page: 1,
    };
  },
  methods: {
    async onLoad() {
      // 异步更新数据
      let res = await getSearch({
        page: this.page,
        per_page: 10,
        q: this.$route.query.value,
      });
      //添加数据
      console.log(res);
      let arr = res.data.data.results;
      this.list.push(...arr);
      this.page++;
      // 加载状态结束
      this.loading = false;

      // 数据全部加载完成
      if (arr.length == 0) {
        this.finished = true;
      }
    },
  },
};
</script>

<style>
</style>